package cn.sxt.oop;

/**
 * 数组拷贝
 */
public class ArrayCopyStady {
    public static void main(String[] args) {
        String[] str = {"aa","bb","cc","dd","ee"};
//        String[] strings = removeElment(str, 4);
        String[] strings = addElment(str,6,"KK");
        for (String item : strings) {
            System.out.println(item);
        }
    }

    //删除数组中指定索引位置的元素，并将原数组返回
    public static String[] removeElment(String[] str,int index){
        System.arraycopy(str,index,str,index-1,str.length-index);
        str[str.length-1] = null;
        return str;
    }

    //向数组中增加指定位置的元素,并返回
    public static String[] addElment(String[] str ,int index , String elment){
        String[] strings = new String[str.length + 1];
        System.arraycopy(str,0,strings,0,index-1);
        strings[index-1] = elment;
        System.arraycopy(str,index-1,strings,index,str.length-index+1);
        return strings;
    }
}
